
{extend name='public/window' /}

{block name="content"}
<style>
  .layui-upload-drag {
    position: relative;
    padding: 10px;
    border: 1px dashed #e2e2e2;
    background-color: #fff;
    text-align: center;
    cursor: pointer;
    color: #999;
    border-radius: 50%;
  }
  .layui-form-label{
    width: 110px;
  }
  .layui-input-block{
    width: 85%;
    margin-left: 146px;
  }
  .layui-input, .layui-textarea {
    display: block;
    width: 80%;
    padding-left: 10px;
  }
  /* .layui-form-select {
      position: absolute;
      right: 165px;
      top: 50%;
      } */
  .layui-form-select .layui-edge {
    position: absolute;
    right: 170px !important;
    top: 50%;
  }
  .layui-form-select dl {
    min-width: 80% !important;
  }
  .layui-form-label {
    width: 116px !important;
  }
</style>
<div class="layui-fluid">
  <div class="layui-card">
    <div class="layui-card-body" style="padding: 15px;">
      <form class="layui-form" action="" lay-filter="form">
        {if isset($info.id)}
        <input type="hidden" name="id" value="{$info.id}">
        {/if}
        <input type="hidden" name="__token__" id="token" value="{:token()}"/>
        <div class="layui-form-item">
          <label class="layui-form-label">组别名称* </label>
          <div class="layui-input-block" >
            <select name="section_id"  lay-filter="section_id" id="section_id">
              <option value="">请选择</option>
              <option value="1">营运一部</option>
              <option value="2">营运二部</option>
              <option value="3">营运三部</option>
              <option value="4">分期</option>
              <option value="5">诉讼</option>
            </select>
          </div>
        </div>
        <div class="layui-form">
          <div class="layui-form-item">
            <label class="layui-form-label">请选择商户</label>
            <div class="layui-input-block">
              <div id="merchant_ids" style="width:80%"></div>
            </div>
          </div>
        </div>

        <div class="layui-form-item">
          <label class="layui-form-label">分组负责人* </label>
          <div class="layui-input-block" >
            <select name="principal_id"  lay-filter="principal_id" id="principal_id">
              <option value="">请选择</option>
              {volist name="admin_list" id="v1"}
              <option value="{$v1.id}">{$v1.nickname}</option>
              {/volist}
            </select>
          </div>
        </div>

        <div class="layui-form-item" id="select_merchant_id">
          <label class="layui-form-label">品牌负责人*</label>
          <div id="admin_se_list" class="layui-input-block">
            {volist name="admin_se_list" id="v"}
            {if $v['selected']==true}
            <input type="checkbox" lay-skin="primary" value='{$v.id}' checked="{$v.selected}" name="principal" title='{$v.nickname}-{$v.username}'>
            {else/}
            <input type="checkbox" lay-skin="primary" value='{$v.id}' name="principal" title='{$v.nickname}-{$v.username}'>
            {/if}
            {/volist}
          </div>
        </div>
        <div class="layui-form-item layui-layout-admin " style="width: 100%">
          <div class="layui-input-block">
            <div class="layui-footer" style="left: 0px;text-align: center;">
              <button class="layui-btn" lay-submit="" lay-filter="add">{:__('Submit')}</button>
              <button type="reset" class="layui-btn layui-btn-primary">{:__('Reset')}</button>
            </div>
          </div>
        </div>

      </form>
    </div>
  </div>
</div>


<script>
  layui.use(['element', 'form', 'jquery','lucky','upload','laydate','xmSelect'], function () {
    var element = layui.element;
    var table = layui.table;
    var form = layui.form;
    var laydate = layui.laydate;
    var $ = layui.jquery;
    var lucky=layui.lucky;
    var xmSelect = layui.xmSelect;
    var xmSelect1 = layui.xmSelect;
    var merchant_list = {:json_encode($merchant_list)};
    var merchant_ids = xmSelect.render({
      el:'#merchant_ids',
      filterable: true,
      data:merchant_list
    })
    // var admin_se_list = {:json_encode($admin_se_list)};
    // var principal = xmSelect1.render({
    //   el:'#principal',
    //   filterable: true,
    //   data:admin_se_list
    // })
    var admin_se_list = {:json_encode($admin_se_list)};
    if(admin_se_list==''){
      $.ajax({
        url:"{:url('getMerchantList')}",
        type:"post",
        data: {},
        dataType:"json",
        success:function(res){
          console.log(res,'选了楼层')
          $.each(res, function(index, item) {
            //赋值
            $('#principal').append('<input type="checkbox" lay-skin="primary" value='+item['id']+' name="principal" title='+item['username']+item['nickname']+'>');
          });
          form.render();
        }
      });
    }

    //表单赋值
    var info = {:json_encode($info)};
    form.val("form",info);
    form.on('submit(add)', function (data) {
      var arr = new Array();
      $("input:checkbox[name='principal']:checked").each(function(i){
        arr[i] = $(this).val();
      });
      //  替换 data.field.level的数据为拼接后的字符串
      data.field.principal = arr.join(",");//将数组合并成字符串
      console.log(data)
      lucky.FormSubmit("{:url('add')}",data.field,true);
      return false;
    });
  })
</script>

{/block}

